package com.yanqu.road.logic.helper;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.entity.union.UnionBaseInfo;
import com.yanqu.road.entity.union.UnionInfo;
import com.yanqu.road.entity.union.cross.CrossUnionInfo;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.List;

public class UnionHelper {
    /**
     * 跨服商会版本请使用CrossUnionMgr.parseUnionBaseInfo
     */
    @Deprecated
    public static UnionBaseInfo parseUnionBaseInfo(UnionInfo unionInfo, UserInfo userInfo, long serverId){
        if(null == unionInfo){
            return null;
        }
        UnionBaseInfo baseInfo = new UnionBaseInfo();
        baseInfo.setUnionAliasId(unionInfo.getUnionAliasId());
        baseInfo.setUnionName(unionInfo.getUnionName());
        baseInfo.setUnionFlag(unionInfo.getUnionFlag());
        baseInfo.setExperience(unionInfo.getExperience());
        baseInfo.setMemberCount(unionInfo.getMemberCount());
        baseInfo.setAllowRandomJoin(unionInfo.isAllowRandomJoin());
        baseInfo.setTotalEarnSpeed(unionInfo.getTotalEarnSpeed());
        baseInfo.setMasterUserId(unionInfo.getMasterUserId());
        baseInfo.setMasterNickName(unionInfo.getMasterNickName());
        baseInfo.setMasterVipExp(unionInfo.getVipExp());
        baseInfo.setMasterDecoration(unionInfo.getDecoration());
        if(unionInfo instanceof CrossUnionInfo){
            CrossUnionInfo crossUnionInfo = (CrossUnionInfo) unionInfo;
            baseInfo.setServerId(crossUnionInfo.getServerId());
            baseInfo.setCross(crossUnionInfo.isCross());
        }else {
            baseInfo.setServerId(serverId);
        }
        if (userInfo != null) {
            baseInfo.setHideVipAndAddress(userInfo.getHideVipAndAddress());
            baseInfo.setSex(userInfo.getSex());
            baseInfo.setMasterVipExp(userInfo.getVipExp());
        }
        return baseInfo;
    }

    public static UnionBaseInfo parseUnionBaseInfoByUserBaseInfo(CrossUnionInfo unionInfo, UserBaseInfo userInfo, long serverId){
        if(null == unionInfo){
            return null;
        }
        UnionBaseInfo baseInfo = new UnionBaseInfo();
        baseInfo.setUnionAliasId(unionInfo.getUnionAliasId());
        baseInfo.setUnionName(unionInfo.getUnionName());
        baseInfo.setUnionFlag(unionInfo.getUnionFlag());
        baseInfo.setExperience(unionInfo.getExperience());
        baseInfo.setMemberCount(unionInfo.getMemberCount());
        baseInfo.setAllowRandomJoin(unionInfo.isAllowRandomJoin());
        baseInfo.setTotalEarnSpeed(unionInfo.getTotalEarnSpeed());
        baseInfo.setMasterUserId(unionInfo.getMasterUserId());
        baseInfo.setMasterVipExp(unionInfo.getVipExp());
        baseInfo.setServerId(serverId);
        baseInfo.setUnionFlagStr(unionInfo.getUnionFlagStr());
        if (userInfo != null) {
            baseInfo.setMasterNickName(userInfo.getNickName());
            baseInfo.setMasterDecoration(userInfo.getDecoration());
            baseInfo.setHideVipAndAddress(userInfo.getHideVipAndAddress());
            baseInfo.setSex(userInfo.getSex());
        }
        return baseInfo;
    }

    public static List<Integer> getUnionFlag(UnionBaseInfo baseInfo){
        List<Integer> result = new ArrayList<>();
        if(StringUtils.isNullOrEmpty(baseInfo.getUnionFlagStr())){
            result.add(baseInfo.getUnionFlag());
        }else {
            result.addAll(StringUtils.stringToIntegerList(baseInfo.getUnionFlagStr(), StringUtils.SPLIT_SEPARATOR));
        }
        return result;
    }

    public static List<Integer> getUnionFlag(CrossUnionInfo unionInfo){
        List<Integer> result = new ArrayList<>();
        if(StringUtils.isNullOrEmpty(unionInfo.getUnionFlagStr())){
            result.add(unionInfo.getUnionFlag());
        }else {
            result.addAll(StringUtils.stringToIntegerList(unionInfo.getUnionFlagStr(), StringUtils.SPLIT_SEPARATOR));
        }
        return result;
    }
}
